package com.englisheveryday.service;

import org.json.JSONObject;

import android.content.Context;

import com.englisheveryday.net.DefaultConnection;
import com.englisheveryday.utils.L;


/**
 * <pre>
 *    
 * </pre>
 * @author 马永华
 * @date 2012-9-16 下午6:40:37
 * @version 1.1
 */

public class SystemService {
	
	private Context context;
	public SystemService(Context context){
		this.context = context;
	}
	
	
	//发表用户反馈
	public boolean feedback(String content){
		try{
		DefaultConnection connection = new DefaultConnection();
		String data = connection.feedback(content);
		if(data==null||"null".equals(data)||"".equals(data))
			return false;
		JSONObject obj = new JSONObject(data).getJSONObject("response");
		if(obj==null)
			return false;
		int result = obj.getInt("result");
		if(result>0){
			return true;
		}
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	//检查更新
	public String checkupdate(double currentVersion){
		L.d("currentVersion:"+currentVersion);
		try{
		DefaultConnection connection = new DefaultConnection();
		String data = connection.checkupdate();
		if(data==null||"null".equals(data)||"".equals(data))
			return null;
		JSONObject obj = new JSONObject(data).getJSONObject("response");
		if(obj==null)
			return null;
		int result = obj.getInt("nowversion");
		if(result>currentVersion){
			return obj.getString("url");
		}
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
		return null;
	}
}

